#ifndef VERTEX2D_H
#define VERTEX2D_H

#include <functional>

namespace RealScan
{

// Represents a point in 2D space
struct Vertex2D
{
    // X and Y coordinates
    double x;
    double y;

    // Constructor to initialize the vertex with given coordinates
    Vertex2D(double _x, double _y) : x(_x), y(_y) {}

    // Equality operator: Checks if two vertices are exactly equal
    bool operator==(const Vertex2D& other) const
    {
        return (x == other.x) && (y == other.y);
    }

    bool operator<=(const Vertex2D& other) const
    {
        return ((x <= other.x) && (y <= other.y));
    }

    // Addition operator: Returns the sum of two vertices
    Vertex2D operator+(const Vertex2D& other) const 
    {
        return {x + other.x, y + other.y};
    }
};

} /* RealScan */

// Specialization of std::hash for the Vertex class
namespace std 
{
    template <>
    struct hash<RealScan::Vertex2D> 
    {
        /// Hash function for a Vertex object
        std::size_t operator()(const RealScan::Vertex2D& vertex) const 
        {
            // Use a stable and combined hash for floating-point numbers
            std::hash<double> doubleHash;
            std::size_t h1 = doubleHash(vertex.x);
            std::size_t h2 = doubleHash(vertex.y);

            // Combine hashes using a common technique
            return h1 ^ (h2 << 1);
        }
    };
}

#endif /* VERTEX2D_H */